﻿@{
    Layout = "~/Views/Shared/_HomeLayout.cshtml";
    ViewBag.Title = "模板";
}
<div class="templatemo-content-widget white-bg">
    <div class="panel panel-default no-border">
        <div class="panel-heading border-radius-10">
            <h2>模板</h2>
        </div>
        <div class="panel-body">
            <div class="templatemo-content-widget no-padding">
                <div class="form-group text-right">
                    <a href="/Template/Add" class="templatemo-white-button">新建</a>
                </div>
                <div class="panel panel-default table-responsive">
                    <table class="table table-striped table-bordered templatemo-user-table" style="table-layout:fixed;" id="app">
                        <thead>
                            <tr>
                                <td style="width:40px">序号</td>
                                <td style="width:200px">模板名称</td>
                                <td>模板描述</td>
                                <td>默认值</td>
                                <td>版本号</td>
                                <td>详情</td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr v-for="item in items">
                                <td>{{item.Num}}</td>
                                <td>{{item.Name}}</td>
                                <td title="{{item.Description}}" class="textDis">{{item.Description}}</td>
                                <td title="{{item.DefaultValue}}" class="textDis">{{item.DefaultValue}}</td>
                                <td>{{item.Version}}</td>
                                <td>
                                    <a href="/Template/Edit?id={{item.Id}}">编辑</a>
                                    <a style="cursor:pointer" v-on:click="deleteT(item.Id)">删除</a>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data: {
            items: []
        },
        methods: {
            deleteT: function (id) {
                this.$http.get('/Template/Delete?id=' + id, function (data, status, request) {
                    if (data) {
                        location.reload();
                    } else {
                        alert("该模板下存在配置，请先删除配置");
                    }
                });
            }
        },
        ready: function () {
            var _self = this;
            _self.$http.get('/Template/GetList', function (data, status, request) {
                $.each(data, function (i, item) {
                    item.Num = i + 1;
                    _self.items.push(item);
                });
            });
        }
    });
</script>
